import { huanJing } from '../../huanJing/HuanJing.js'

// dialog不能attachShadow
export class KaiShiCaiDan extends HTMLDialogElement {
	kaiShiResolve = null
	kaiShiAnNiu = null
	daoRuCunDangAnNiu = null
	
	constructor() {
		super()
		
		let style = document.createElement('style')
		style.textContent = `
			kai-shi-an-niu:hover {
				filter: hue-rotate(90deg) brightness(1.3) drop-shadow(0px 0px 10px rgba(100, 100, 255, 1.0));
			}
		`
		this.appendChild(style)

		this.kaiShiAnNiu = document.createElement('kai-shi-an-niu')
		this.kaiShiAnNiu.insertAdjacentHTML('beforeend', `<span>开始</span>`)
		this.kaiShiAnNiu.onpointerup = () => {
			this.close()
			if (this.kaiShiResolve) this.kaiShiResolve()
			let huaBu = huanJing.renderer.domElement
			huaBu.focus()
		}
		this.appendChild(this.kaiShiAnNiu)
		
		this.daoRuCunDangAnNiu = document.createElement('kai-shi-an-niu')
		this.daoRuCunDangAnNiu.insertAdjacentHTML('beforeend', `<span>导入存档</span>`)
		this.appendChild(this.daoRuCunDangAnNiu)
	}

	connectedCallback() {
		this.style.setProperty('background', 'none')
		this.style.setProperty('position', 'fixed')
		this.style.setProperty('inset', '0')
		this.style.setProperty('z-index', '100')
	}
	
	kaiShi() {
		return new Promise(resolve => {
			this.kaiShiResolve = resolve
		})
	}
}

customElements.define("kai-shi-cai-dan", KaiShiCaiDan, { extends: "dialog" })

